
package com.c2dm.servlets;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;


@SuppressWarnings("serial")
public class SendServlet extends HttpServlet
{

	private final static String AUTH = "authentication";
	// Evil hard code the auth_key
	private static final String UPDATE_CLIENT_AUTH = "Update-Client-Auth";
	
	public static final String PARAM_REGISTRATION_ID = "registration_id";
	
	public static final String PARAM_DELAY_WHILE_IDLE = "delay_while_idle";

	private static final Logger log = Logger.getLogger(SendServlet.class.getName());
			
	public static final String PARAM_COLLAPSE_KEY = "collapse_key";

	private static final String UTF8 = "UTF-8";

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{
		String facebook_id = req.getParameter("facebook_id");
		String msg = req.getParameter("msg");
        com.c2dm.data.MessageUtil.sendInformativeMessage(facebook_id, msg);
	}

	private String getStoredAuthenticationCode() 
	{
		// Entity entity = new Entity("token", "mytoken");
		// entity.setProperty("authkey", token);
		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		Key todoKey = KeyFactory.createKey("token", "mytoken");
		Entity entity;
		try
		{
			entity = datastore.get(todoKey);
			String token = (String) entity.getProperty("authkey");
			return token;
		} 
		catch (EntityNotFoundException e) 
		{
			// Log.setContentType("text/plain");
			// resp.getWriter().println("Entry not found.");
		}
		throw new RuntimeException("No authentication tooken");
	}
}